package com.jingsheng.jingshengcity.mvp.ui.fragment.tab;

import android.content.Intent;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jess.arms.base.BaseFragment;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.UiUtils;
import com.jingsheng.jingshengcity.R;
import com.jingsheng.jingshengcity.di.component.DaggerMineFragmentComponent;
import com.jingsheng.jingshengcity.di.module.MineFragmentModule;
import com.jingsheng.jingshengcity.mvp.contract.MineFragmentContract;
import com.jingsheng.jingshengcity.mvp.presenter.MineFragmentPresenter;
import com.jingsheng.jingshengcity.mvp.ui.activity.MyOrderActivity;
import com.jingsheng.jingshengcity.mvp.ui.activity.address.AddressListActivity;
import com.jingsheng.jingshengcity.mvp.ui.activity.authentication.MemberAuthenticationActivity;
import com.jingsheng.jingshengcity.mvp.ui.activity.authentication.MemberAuthenticationAlreadyActivity;
import com.jingsheng.jingshengcity.mvp.ui.activity.wallet.WalletActivity;

import butterknife.BindView;

import static com.jess.arms.utils.Preconditions.checkNotNull;


/**
 * Created by Administrator on 2017/5/5.
 */

public class MineFragment extends BaseFragment<MineFragmentPresenter> implements MineFragmentContract.View, View.OnClickListener {

    @NonNull
    @BindView(R.id.tv_all_order)
    TextView mTvAllOrder;
    @NonNull
    @BindView(R.id.ll_wallet)
    LinearLayout mLLWallet;
    @NonNull
    @BindView(R.id.ll_member_authentication)
    LinearLayout mLLMemberAuthentication;
    @NonNull
    @BindView(R.id.ll_address)
    LinearLayout mLLAddress;

    public static MineFragment newInstance() {
        MineFragment fragment = new MineFragment();
        return fragment;
    }

    @Override
    public void setupFragmentComponent(AppComponent appComponent) {
        DaggerMineFragmentComponent
                .builder()
                .appComponent(appComponent)
                .mineFragmentModule(new MineFragmentModule(this))
                .build()
                .inject(this);
    }

    @Override
    public View initView(LayoutInflater inflater, ViewGroup container) {
        return inflater.inflate(R.layout.fragment_mine, container, false);
    }

    @Override
    public void initData() {
        initEvent();
    }

    private void initEvent() {
        mTvAllOrder.setOnClickListener(this);
        mLLWallet.setOnClickListener(this);
        mLLMemberAuthentication.setOnClickListener(this);
        mLLAddress.setOnClickListener(this);
    }


    @Override
    public void setData(Object data) {

    }


    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        UiUtils.SnackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        UiUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_all_order:
                toMyOrder();
                break;
            case R.id.ll_wallet:
                toWallet();
                break;
            case R.id.ll_member_authentication:
                toAuthentication();
                break;
            case R.id.ll_address:
                toAddress();
                break;
        }
    }

    private void toAddress() {
        Intent intent = new Intent(getActivity(), AddressListActivity.class);
        startActivity(intent);
    }

    private void toAuthentication() {
        if (true) {
            Intent intent = new Intent(getActivity(), MemberAuthenticationAlreadyActivity.class);
            startActivity(intent);
        } else {
            Intent intent = new Intent(getActivity(), MemberAuthenticationActivity.class);
            startActivity(intent);
        }
    }

    private void toWallet() {
        Intent intent = new Intent(getActivity(), WalletActivity.class);
        startActivity(intent);
    }

    private void toMyOrder() {
        Intent intent = new Intent(getActivity(), MyOrderActivity.class);
        startActivity(intent);
    }
}